using UnityEngine;
using System.Collections;

public class AttackDecision : MonoBehaviour {
	
	public enum RangeType {
		Circle,
		Cone,
		Box
	}
	
	public Vector3 centerPoint;
	public RangeType rangeType;
	public float fLength, fWidth, fHeight, fRadius, fWidthAngle;
	
	
	public AttackDecision()
	{
		rangeType = RangeType.Circle;
		fLength = 10;
		fWidth = 10;
		fHeight = 10;
		fRadius = 10;
		fWidthAngle = 10;
		
	}
	
	public AttackDecision(RangeType rngType, float length, float width, float height, float radius, float angle) {
		rangeType = rngType;
		
		fLength = length;
		fWidth = width;
		fHeight = height;
		fRadius = radius;
		fWidthAngle = angle;
	}
	
	// Use this for initialization
	void Start () {
		fRadius = 30.0f;
		fWidthAngle = 30.0f;
		fWidth = 8.0f;
		fLength = 20.0f;
		rangeType = RangeType.Box;
	}
	
	public bool checkTarget(Defender def) {
		return checkTarget(def.transform.position);
	}
	
	public bool checkTarget(Vector3 pos) {
		switch (rangeType) {
		case RangeType.Circle:
			if (Vector3.Distance(transform.position, pos) < fRadius)
			{ return true; }
			break;
		case RangeType.Cone:
			// get dot product between defender and attacker
			float d1 = Vector3.Dot(Vector3.Normalize(transform.position - pos), transform.rotation * Vector3.forward);
			// get minimun dot product of getting hit
			float d2 = Vector3.Dot(Vector3.Normalize(transform.position - (Quaternion.Euler(0,fWidthAngle/2,0) * (transform.rotation * (Vector3.forward * 10)) + transform.position)), transform.rotation * Vector3.forward);
			if ( (d1 < d2) && (Vector3.Distance(transform.position, pos) < fRadius) )
			{ return true; }
			break;
		case RangeType.Box:
			if ( Mathf.Abs((transform.position.x - pos.x)) < fWidth && Mathf.Abs((transform.position.z - pos.z)) < fLength ) {
				return true;
			}
			break;
		default: return false;
		}
		return false;
	}
	
	// Update is called once per frame
	void Update () {
		
	/*	for (int i = 0; i < 50; i++) {
		Vector3 tempPoint = new Vector3(Random.Range(-70.0f, 70.0f), 0.0f, Random.Range(-70.0f, 70.0f));
		if (checkTarget(tempPoint)) {
			GameObject temp = (GameObject)GameObject.Instantiate(GameObject.Find("Cube"));
			temp.transform.position = tempPoint;
		}
		}*/
	}
}
